package org.example.hadoop.service.wordFrequency;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author wwy
 * @date 2020-11-08 14:32
 */
public class WordFrequencyReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
    /**
     * 统计次数
     * @param key
     * @param values
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int count = 0;
        for (IntWritable iw : values) {
            count += iw.get();
        }
        context.write(key,new IntWritable(count));
    }
}
